package com.trickytriad.tasks.game
{
	import com.trickytriad.events.game.GetGameDataEvent;
	import com.trickytriad.model.repositories.R_GameData;
	
	import flash.events.ErrorEvent;
	
	import org.spicefactory.lib.task.Task;

	/**
	 * Task that retrieves the GameData for the specified id.
	 */
	public class GetGameDataTask extends Task
	{
		private var _gameid:uint;
		private var _handler:Function;
		
		[Bindable]
		[Inject]
		public var r_gamedata:R_GameData; 
		
		/**
		 * Constructor.  Accepts the gameid which we're looking for.
		 * @param uint GameID to accept
		 * @param Function Function pointer to the completion function.  Should accept a parameter of "GameData".
		 */
		public function GetGameDataTask(in_gameid:uint, in_completeHandler:Function=null)
		{
			super();
			_gameid = in_gameid;
			_handler = in_completeHandler;
			setCancelable(false);
			setSkippable(false);
			setSuspendable(false);
		}
		/**
		 * Starts up the gamedata task.
		 */
		protected override function doStart () : void {
			
	    }
		
		/**
		 * Function that is called on complete.  If there's a function handler, it calls that,
		 * then calls the complete() function (for sequential tasking, etc.)
		 */
	    private function onComplete (evt:GetGameDataEvent) : void {
	    	if (_handler != null)
	        	_handler(evt.gdata);
	        complete();
	    }
		
	    private function onError (event:ErrorEvent) : void {
	       
	    }
		
		
	}
}